package cc.rengu.redp.bizimpl.upmp.controller;


import cc.rengu.redp.bizimpl.upmp.domain.BCardBlacklistInfo;
import cc.rengu.redp.bizimpl.upmp.service.IBCardBlacklistInfoService;
import cc.rengu.redp.common.annotation.Log;
import cc.rengu.redp.common.controller.BaseController;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * @author lizk
 */
@RestController
@Slf4j
@RequestMapping("/admin/merParam/cardBlackListInfo")
public class BCardBlacklistInfoController extends BaseController {

    @Autowired
    private IBCardBlacklistInfoService cardBlacklistInfoService;

    @GetMapping
    public Map<String, Object> findByPage(QueryRequest queryRequest, BCardBlacklistInfo cardBlacklistInfo) {
        return getDataTable(cardBlacklistInfoService.findByPage(queryRequest, cardBlacklistInfo));
    }


    @Log("新增卡号黑名单")
    @PostMapping
//    @RequiresPermissions("brand:add")
    public void addCardBlack(@Valid BCardBlacklistInfo cardBlacklistInfo) throws RedpException {

        try {
            this.cardBlacklistInfoService.createCardBlack(cardBlacklistInfo);
        } catch (Exception e) {
            String message = e.getMessage();
            log.error(message, e);
            throw new RedpException(message);
        }
    }

    @Log("修改卡号黑名单")
    @PutMapping
//    @RequiresPermissions("brand:update")
    public void updateCardBlack(BCardBlacklistInfo cardBlacklistInfo) throws RedpException {
        try {
            this.cardBlacklistInfoService.updateCardBlack(cardBlacklistInfo);
        } catch (Exception e) {
            String message = e.getMessage();
            log.error(message, e);
            throw new RedpException(message);
        }
    }

}
